! function() {

	var Factory = function() {}

	/* -----------------------------
	 * 队列
	 * add: 添加队列
	 * list: 存储队列
	 * deal: 处理队列
	 * impl: 执行队列
	 * jude: 队列可执行状态
	 * --------------------------- */
	Factory.prototype.queue = {
		add: function(exports) {
			var that = this;
			that.list.push(exports);
			that.deal();
		},
		list: [],
		deal: function() {
			var that = this;
			if(that.jude === true) {
				that.jude = false;
				that.impl();
			}
		},
		impl: function() {
			var that = this;
			if(that.list.length >= 1) {
				var fn = that.list[0];
				that.list.shift();
				fn(function() {
					that.jude = true;
					that.deal();
					that.jude = true;
				});
			}
		},
		jude: true
	}

	/* -----------------------------
	 * 请求API
	 * --------------------------- */
	Factory.prototype.interface = function() {
		var itce = new Interface(arguments[0]);
	}

	/* -----------------------------
	 * 发起请求
	 * --------------------------- */
	Factory.prototype.request = function(name, unkn) {
		var config = Configure[name];
		if(!config) {
			tool.p('无法找到配置文件:' + name + ', 已终止请求.');
			return;
		}

		// 复制对象
		var opts = tool.optionExtend({}, config);

		unkn && (opts['unkn'] = unkn);

		/* -----------------------------
		 * 向工厂发起数据请求并添加至队列
		 * --------------------------- */
		factory.queue.add(function(callback) {
			factory.handle(opts);
			callback();
		});
	};

	/* -----------------------------
	 * 处理请求
	 * --------------------------- */
	Factory.prototype.handle = function(opts) {
		var that = this;

		// 请求数据
		if(typeof opts.data != 'undefined') opts.data = formatParam(opts.data);

		// 请求头
		if(typeof opts.header != 'undefined') opts.header = formatParam(opts.header);

		var unkn = opts.unkn;
		delete opts.unkn;

		// 重写请求回调
		var complete = opts.complete;
		if(typeof complete == 'string') {
			if(typeof window[complete] == 'function') {
				opts['complete'] = function(res) {
					eval(complete)(res, unkn);
				}
			} else {
				tool.p('回调函数未定义: ' + complete);
				return null;
			}
		}
		ajax(opts);
	};

	/* -----------------------------
	 * 处理参数
	 * --------------------------- */
	function formatParam(param) {
		// 判断是否string并且是function
		if(typeof param == 'string') {
			if(typeof window[param] == 'function') {
				// 执行方法并返回结果
				return eval(param)();
			} else if (typeof window[param] == 'object' && window[param] instanceof Object) {
				return window[param];
			} else {
				tool.p('未定义: ' + param);
				return null;
			}
		}

		// 常规流程
		var data_opt = {};
		for(var i in param) {
			var p = param[i];
			switch(p[0]) {
				case 'string':
					data_opt[i] = p[1];
					break;
				case 'array':
					break;
				case 'object':
					break;
				case 'dom':
					if(p[2] == 'value') {
						data_opt[i] = $(p[1]).val();
					} else {
						data_opt[i] = $(p[1]).attr(p[2]);
					}
					break;
				case 'cmd':
					data_opt[i] = eval(p[1]);
					break;
				case 'storage':
					data_opt[i] = tool.__storage.get(p[1]);
					break;
				case 'fn':
					break;
				default:
					break;
			}
			if(p[p.length - 1] == 'md5') {
				data_opt[i] = md5(data_opt[i]);
			}
		}
		return data_opt;
	}

	window.factory = new Factory();
}();